package com.kaili.pojo.dto.ewb;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.kaili.common.util.CommonRegexUtil;
import com.kaili.pojo.vo.CustomerVO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @author xjh
 * @ClassName EwbAddDTO
 * @Description 托运开单新增实体类
 * @Date 下午2:13 18-5-22
 * @Version 1.0
 */
@Data
public class EwbAddDTO implements Serializable{
    @Pattern(regexp = "^[A-Za-z0-9]{0,30}$",message = "预约号应为[A-Za-z0-9]组成的1-30位字符")
    @ApiModelProperty("预约单号")
    private String appointNo;

    @Pattern(regexp = "^\\d{0,19}$",message = "运单主键应为[0-9]组成的1-19位字符")
    @ApiModelProperty("运单主键")
    private String operationId;

    @Pattern(regexp = CommonRegexUtil.REGEX_EWB_NO,message = "运单号应为[A-Za-z0-9]组成的1-30位字符")
    @ApiModelProperty("托运单号")
    private String ewbNo;

    @ApiModelProperty("开单时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date ewbDate;

    @NotNull(message = "是否签回单不能为空")
    @ApiModelProperty("是否签回单")
    private Integer isRewb;//签回单

//    @ApiModelProperty("开单操作人id")
//    private String operatorId;

    @NotNull(message = "寄件网点id不能为空")
    @ApiModelProperty("寄件网点id")
    private Integer sendSiteId;

    @NotNull(message = "目的网点id不能为空")
    @ApiModelProperty("目的网点id")
    private Integer dispatchSiteId;//目的网点

    @NotNull(message = "目的地id不能为空")
    @ApiModelProperty("目的地id")
    private Integer cityId;//目的地

    @Size(min=1,max=4,message = "货物明细应为1-4件")
    @Valid
    private List<GoodsDetailAddBean> goodsDetailList;

    private CustomerDTO sendCustomer;

//    @NotNull(message = "寄件人id不能为空")
    @ApiModelProperty("寄件人id")
    private Integer sendCustomerId;

    private CustomerDTO receiveCustomer;

//    @NotNull(message = "收件人id不能为空")
    @ApiModelProperty("收件人id")
    private Integer receiveCustomerId;

    @NotNull(message = "派送自提id不能为空")
    @ApiModelProperty("派送自提id")
    private Integer pickGoodsModeId;//派送自提

    @ApiModelProperty("代收货款")
    private BigDecimal codCharge = new BigDecimal(0);//代收货款

    @NotNull(message = "保价金额不能为空")
    @ApiModelProperty("保价金额")
    private BigDecimal insuredAmount = new BigDecimal(0);//保价金额

    @NotNull(message = "是否易碎品不能为空")
    @ApiModelProperty("是否易碎品")
    private Integer isFragile;//是否易碎品

    @NotNull(message = "派送费不能为空")
    @ApiModelProperty("派送费")
    private BigDecimal sendCharge;//派送费

    @NotNull(message = "总费用不能为空")
    @ApiModelProperty("总费用")
    private BigDecimal totalAmount;//总费用

    @ApiModelProperty("代收货款手续费")
    private BigDecimal receiveSendCodCharge = new BigDecimal(0);//代收货款手续费

    @ApiModelProperty("保费")
    private BigDecimal dobInsuranceFee = new BigDecimal(0);;//保费

    @ApiModelProperty("接货费")
    private BigDecimal deliveryCharge = new BigDecimal(0);//接货费

    @NotNull(message = "结算方式id不能为空")
    @ApiModelProperty("结算方式id")
    private Integer settleModeId;//结算方式

    @NotNull(message = "支付方式id不能为空")
    @ApiModelProperty("支付方式id")
    private Integer payModeId;//支付方式

    @ApiModelProperty("业务费")
    private BigDecimal businessCharge = new BigDecimal(0);//业务费

    @Length(min=0,max=100,message = "备注长度在[0,100]之间")
    @ApiModelProperty("备注")
    private String remark;//备注

    @NotNull(message = "总件数不能为空")
    @ApiModelProperty("总件数")
    private Integer totalPiece;//总件数

    @NotNull(message = "总重量不能为空")
    @ApiModelProperty("总重量")
    private BigDecimal totalWeight;//总重量

    @NotNull(message = "总体积不能为空")
    @ApiModelProperty("总体积")
    private BigDecimal totalVol;//总体积

    @NotNull(message = "总运费不能为空")
    @ApiModelProperty("总运费")
    private BigDecimal totalFreightCharge;//总运费

    @ApiModelProperty("货源id")
    private Integer supplyId;//货源id

    @NotNull(message = "来源不能为空")
    @ApiModelProperty("来源,1标示web端,2标示PDA端")
    private Integer sourceType;

    public void setDeliveryCharge(BigDecimal deliveryCharge) {
        if(deliveryCharge == null){
            deliveryCharge = new BigDecimal(0);
        }
        this.deliveryCharge = deliveryCharge;
    }

    public void setBusinessCharge(BigDecimal businessCharge) {
        if(businessCharge == null){
            businessCharge = new BigDecimal(0);
        }
        this.businessCharge = businessCharge;
    }

    public void setInsuredAmount(BigDecimal insuredAmount) {
        if(insuredAmount == null){
            insuredAmount = new BigDecimal(0);
        }
        this.insuredAmount = insuredAmount;
    }

    public void setDobInsuranceFee(BigDecimal dobInsuranceFee) {
        if(dobInsuranceFee == null){
            dobInsuranceFee = new BigDecimal(0);
        }
        this.dobInsuranceFee = dobInsuranceFee;
    }

    public void setReceiveSendCodCharge(BigDecimal receiveSendCodCharge) {
        if(receiveSendCodCharge == null){
            receiveSendCodCharge = new BigDecimal(0);
        }
        this.receiveSendCodCharge = receiveSendCodCharge;
    }

    public void setCodCharge(BigDecimal codCharge) {
        if(codCharge == null){
            codCharge = new BigDecimal(0);
        }
        this.codCharge = codCharge;
    }
}
